package com.yyj.dao;

import com.yyj.entity.*;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserDao {
    List<Pet> getDog(@Param("petParams") PetParams petParams);
    List<Pet> getCat(@Param("petParams") PetParams petParams);
    List<User> getBySearch(@Param("params") Params params);
    /*@Select("SELECT * FROM pet WHERE originalOwnerId = #{userId}")
    User getUserWithPetByUserId(Integer userId);*/
    @Insert("insert into user (name,password,sex,age,phone,role) values (#{name },'123456',#{sex},#{age},#{phone},'ROLE_USER')")
    void insertUser(User user);
    @Update("update user set name=#{name},password=#{password},sex=#{sex},age=#{age},phone=#{phone} where userId=#{userId}")
    void updateUser(User user);
    @Delete("DELETE FROM user WHERE userId = #{userId}")
    void deleteByPrimaryKey(Integer userId);
    @Insert("insert into user (name,password,sex,age,phone) values (#{name },#{password},#{sex},#{age},#{phone})")
    void insert(User user);
    @Select("select * from user where name=#{name} and password=#{password}")
    User login(User user);
    @Select("select * from user where name=#{name} limit 1")
    User findByName(@Param("name") String name);

    @Insert("insert into pet(name,image,variety,age,address,description,originalOwnerId,chat,species,currentTime,status) values (#{name},#{image},#{variety},#{age},#{address},#{description},#{originalOwnerId},#{chat},#{species},now(),'待领养')")
    void insertDog(Pet pet);

    @Insert("insert into pet(name,image,variety,age,address,description,originalOwnerId,chat,species,currentTime,status) values (#{name},#{image},#{variety},#{age},#{address},#{description},#{originalOwnerId},#{chat},#{species},now(),'待领养')")
    void insertCat(Pet pet);
    @Select("select * from user where userId=#{id}")
    User findById(Integer id);
    @Update("update pet set name=#{name},image=#{image},variety=#{variety},age=#{age},address=#{address},description=#{description},originalOwnerId=#{originalOwnerId},chat=#{chat},species=#{species},currentTime=now() where petId=#{petId}")
    void update(Pet pet);

    @Delete("delete from pet where petId=#{petId}")
    void delete(Integer petId);

    @Update("update user set name=#{name},password=#{password},sex=#{sex},age=#{age},phone=#{phone},avatar=#{avatar} where userId=#{userId}")
    void updateImg(User user);

    @Update("update user set name=#{name},password=#{password},sex=#{sex},age=#{age},phone=#{phone},avatar=#{avatar} where userId=#{userId}")
    void updatePwd(Integer userId);

    @Select("select * from pet where newOwner=#{newOwner}")
    List<Pet> findByNewOwner(Integer newOwner);


}
